package janelas;

import outros.CampoMask;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import outros.GeradorRelatorio;
import outros.Util;
import persistencia.DAOArea;
import persistencia.DAOFornecedor;
import persistencia.DAOGenerico;
import persistencia.DAOGrupo;
import persistencia.DAOSetor;
import persistencia.DAOSubgrupo;
import transporte.TOArea;
import transporte.TOFornecedor;
import transporte.TOGenerico;
import transporte.TOGrupo;
import transporte.TOPai;
import transporte.TOSetor;
import transporte.TOSubgrupo;

public class RelatorioBem extends javax.swing.JInternalFrame implements JanelaPai {
    //DAO's
    private DAOArea daoArea = new DAOArea();
    private DAOGrupo daoGrupo = new DAOGrupo();
    private DAOSubgrupo daoSubgrupo = new DAOSubgrupo();
    private DAOSetor daoSetor = new DAOSetor();
    private DAOFornecedor daoFornecedor = new DAOFornecedor();
    private DAOGenerico daoOrgao = new DAOGenerico();
    //TO's
    private ArrayList<TOArea> toArea = new ArrayList();
    private ArrayList<TOGrupo> toGrupo = new ArrayList();
    private ArrayList<TOSubgrupo> toSubgrupo = new ArrayList();
    private ArrayList<TOSetor> toSetor = new ArrayList();
    private ArrayList<TOFornecedor> toFornecedor = new ArrayList();
    private ArrayList<TOGenerico> toOrgao = new ArrayList();
    //
    private GeradorRelatorio gr = null;
    private Util util = new Util();
    private Thread thread;

    public RelatorioBem() {
        initComponents();
        barra.setString("Gerando relatório...");
        botCancelar.setEnabled(false);
        botGerar.setEnabled(true);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-getWidth())/2, (int)((screenSize.height-getHeight())/3), getWidth(), getHeight());
    }

    private void limparCampos() {
        checkArea.setSelected(false);
        camArea.setSelectedIndex(0);
        camArea.setEnabled(false);
        checkGrupo.setSelected(false);
        camGrupo.setSelectedIndex(0);
        camGrupo.setEnabled(false);
        checkSubgrupo.setSelected(false);
        checkSubgrupo.setEnabled(false);
        camSubgrupo.setSelectedIndex(0);
        camSubgrupo.setEnabled(false);
        checkSetor.setSelected(false);
        camSetor.setEnabled(false);
        camSetor.setSelectedIndex(0);
        checkFornecedor.setSelected(false);
        camFornecedor.setSelectedIndex(0);
        camFornecedor.setEnabled(false);
        checkOrgao.setSelected(false);
        camOrgao.setSelectedIndex(0);
        camOrgao.setEnabled(false);
        checkBaixa.setSelected(false);
        radioBaixaSim.setSelected(true);
        radioBaixaSim.setEnabled(false);
        radioBaixaNao.setEnabled(false);
        checkData.setSelected(false);
        camDataInicial.setText("");
        camDataInicial.setEnabled(false);
        camDataFinal.setText("");
        camDataFinal.setEnabled(false);
        checkPenhora.setSelected(false);
        radioPenhoraSim.setSelected(true);
        radioPenhoraSim.setEnabled(false);
        radioPenhoraNao.setEnabled(false);
        checkComodato.setSelected(false);
        radioComodatoSim.setSelected(true);
        radioComodatoSim.setEnabled(false);
        radioComodatoNao.setEnabled(false);
        radioAnalitico.setSelected(true);
        camOrdem.setSelectedIndex(0);
    }

    private void preencherComboBox() {
        camArea.removeAllItems();
        camGrupo.removeAllItems();
        camSetor.removeAllItems();
        camFornecedor.removeAllItems();
        camOrgao.removeAllItems();
        for (int i=0;i<toArea.size();i+=1) {
            camArea.addItem(toArea.get(i).getNome());
        }
        for (int i=0;i<toGrupo.size();i+=1) {
            camGrupo.addItem(toGrupo.get(i).getNome());
        }
        for (int i=0;i<toSetor.size();i+=1) {
            camSetor.addItem(toSetor.get(i).getNome());
        }
        for (int i=0;i<toFornecedor.size();i+=1) {
            camFornecedor.addItem(toFornecedor.get(i).getNome());
        }
        for (int i=0;i<toOrgao.size();i+=1) {
            camOrgao.addItem(toOrgao.get(i).getNome());
        }
        trocarSubgrupos();
        limparCampos();
    }

    private void trocarSubgrupos() {
        camSubgrupo.removeAllItems();
        int grupo = toGrupo.get(camGrupo.getSelectedIndex()).getNumero();
        try {
            toSubgrupo = daoSubgrupo.getSubgruposPorGrupo(grupo);
            for (int i=0;i<toSubgrupo.size();i+=1) {
                camSubgrupo.addItem(toSubgrupo.get(i).getNome());
            }
        } catch (Exception e) {}
    }

    public void reiniciar() {
        toArea = daoArea.selecionar("");
        toGrupo = daoGrupo.selecionar("");
        toSubgrupo = daoSubgrupo.getSubgruposPorGrupo(toGrupo.get(0).getNumero());
        toFornecedor = daoFornecedor.selecionar("");
        toSetor = daoSetor.selecionar("");
        toOrgao = daoOrgao.selecionarGenerico("orgao", "nome");
        preencherComboBox();
    }

    private ArrayList<String> getCondicoes(String tipo) {
        ArrayList<String> cond = new ArrayList();
        if (checkArea.isSelected()) {
            cond.add("patri_patrimonio.area="+toArea.get(camArea.getSelectedIndex()).getNumero());
        }
        if (checkGrupo.isSelected()) {
            cond.add("patri_patrimonio.grupo="+toGrupo.get(camGrupo.getSelectedIndex()).getNumero());
            if (checkSubgrupo.isSelected()) {
                cond.add("patri_patrimonio.subgrupo="+toSubgrupo.get(camSubgrupo.getSelectedIndex()).getNumero());
            }
        }
        if (checkSetor.isSelected()) {
            cond.add("patri_patrimonio.lotacao="+toSetor.get(camSetor.getSelectedIndex()).getNumero());
        }
        if (checkFornecedor.isSelected()) {
            cond.add("patri_patrimonio.fornecedor="+toFornecedor.get(camFornecedor.getSelectedIndex()).getNumero());
        }
        if (checkOrgao.isSelected()) {
            cond.add("patri_patrimonio.orgao="+toOrgao.get(camOrgao.getSelectedIndex()).getNumero());
        }
        if (checkBaixa.isSelected()) {
            if (radioBaixaSim.isSelected()) {
                cond.add("patri_patrimonio.baixa=1");
            } else {
                cond.add("patri_patrimonio.baixa<>1");
            }
        }
        if (checkPenhora.isSelected()) {
            if (radioPenhoraSim.isSelected()) {
                cond.add("patri_patrimonio.penhora=1");
            } else {
                cond.add("patri_patrimonio.penhora=0");
            }
        }
        if (checkComodato.isSelected()) {
            if (radioComodatoSim.isSelected()) {
                cond.add("patri_patrimonio.comodato=1");
            } else {
                cond.add("patri_patrimonio.comodato=0");
            }
        }
        if (!tipo.equals("ana")) {
            cond.add("patri_patrimonio.situacao=patri_situacao.numero");
        }
        return cond;
    }

    private String montaSQL(String tipo) {
        ArrayList<String> cond = getCondicoes(tipo);
        String sql = "";
        if (tipo.equals("ana")) {
            sql = "SELECT patri_patrimonio.area as numArea, patri_area.nome as area, "+
                  "patri_patrimonio.grupo as numGrupo, patri_grupo.nome as grupo, "+
                  "patri_patrimonio.subgrupo as numSubgrupo, patri_subgrupo.nome as subgrupo, "+
                  "patri_patrimonio.numero as numPatrimonio, patri_patrimonio.nome as patrimonio, "+
                  "CASE patri_patrimonio.baixa WHEN 1 THEN 'Sim' ELSE 'Não' END as baixa, patri_baixa.nome as tipoBaixa, "+
                  "patri_patrimonio.baixa_data as dataBaixa, patri_patrimonio.data_entrada as dataEntrada, "+
                  "patri_fornecedor.nome as fornecedor, patri_setor.nome as setor, "+
                  "patri_patrimonio.nf_data as dataNF, patri_patrimonio.chassi as chassi, "+
                  "patri_patrimonio.nf_numero as numeroNF, patri_patrimonio.processo as processo, "+
                  "patri_patrimonio.serie as serie, CASE patri_patrimonio.aquisicao WHEN 1 THEN 'Compra' WHEN 2 THEN 'Doação' WHEN 3 THEN 'Leasing' WHEN 4 THEN 'Fabricação' WHEN 5 THEN 'Outros' ELSE 'Outros' END as aquisicao, "+
                  "CASE patri_patrimonio.tipo WHEN 2 THEN 'Empréstimo' ELSE 'Aquisição' END as tipo FROM"+
                  " patri_patrimonio LEFT JOIN patri_area ON (patri_patrimonio.area=patri_area.numero)"+
                  " LEFT JOIN patri_grupo ON (patri_patrimonio.grupo=patri_grupo.numero)"+
                  " LEFT JOIN patri_subgrupo ON (patri_patrimonio.subgrupo=patri_subgrupo.numero AND patri_patrimonio.grupo=patri_subgrupo.grupo)"+
                  " LEFT JOIN patri_setor ON (patri_patrimonio.lotacao=patri_setor.numero)"+
                  " LEFT JOIN patri_fornecedor ON (patri_patrimonio.fornecedor=patri_fornecedor.numero)"+
                  " LEFT JOIN patri_baixa ON (patri_patrimonio.baixa_tipo=patri_baixa.numero)";
        } else {
            sql = "SELECT patri_patrimonio.area, patri_patrimonio.grupo, patri_patrimonio.subgrupo, patri_patrimonio.numero, patri_patrimonio.nome as descricao, patri_patrimonio.valor_final_real as valor, patri_patrimonio.serie, patri_situacao.nome as situacao FROM patri_patrimonio, patri_situacao";
        }
        boolean primeira = false;
        for (int i=0;i<cond.size();i+=1) {
            if (!primeira) {
                sql += " WHERE ";
                primeira = true;
            } else {
                sql += " AND ";
            }
            sql += cond.get(i);
        }
        if (checkData.isSelected()) {
            if (!primeira) {
                sql += " WHERE ";
                primeira = true;
            } else {
                sql += " AND ";
            }
            sql += "patri_patrimonio.data_entrada BETWEEN '"+util.dataToStringBarra(camDataInicial.getText(), "-")+"' AND '"+util.dataToStringBarra(camDataFinal.getText(), "-")+"'";
        }
        if (camOrdem.getSelectedIndex()==0) {
            sql += " ORDER BY patri_patrimonio.nome ASC";
        } else {
            sql += " ORDER BY patri_patrimonio.data_entrada ASC";
        }
        System.out.println(sql);
        return sql;
    }

    private void cancelarThread() {
        try {
            thread.stop();
            System.out.println("Parando thread...");
        } catch (Exception e) {
            System.out.println("Erro ao tentar para thread. Erro: "+e.getMessage());
        } finally {
            barra.setStringPainted(false);
            barra.setIndeterminate(false);
        }
    }

    private boolean setarCombo(String n, String nome, ArrayList lista, JComboBox campo) {
        int num = Integer.parseInt(n);
        for (int i=0;i<lista.size();i+=1) {
            if (((TOPai)lista.get(i)).getNumero()==num) {
                campo.setSelectedIndex(i);
                //proxCampo.requestFocus();
                return true;
            }
        }
        JOptionPane.showMessageDialog(null, nome+" inexistente.");
        return false;
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grupoBaixa = new javax.swing.ButtonGroup();
        grupoPenhora = new javax.swing.ButtonGroup();
        grupoComodato = new javax.swing.ButtonGroup();
        grupoTipo = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        checkArea = new javax.swing.JCheckBox();
        camArea = new javax.swing.JComboBox();
        camAreaNum = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        checkGrupo = new javax.swing.JCheckBox();
        camGrupo = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        checkSubgrupo = new javax.swing.JCheckBox();
        camSubgrupo = new javax.swing.JComboBox();
        camSubgrupoNum = new javax.swing.JTextField();
        camGrupoNum = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        checkFornecedor = new javax.swing.JCheckBox();
        camFornecedor = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        checkSetor = new javax.swing.JCheckBox();
        camSetor = new javax.swing.JComboBox();
        jPanel7 = new javax.swing.JPanel();
        checkOrgao = new javax.swing.JCheckBox();
        camOrgao = new javax.swing.JComboBox();
        jPanel9 = new javax.swing.JPanel();
        camDataInicial = new CampoMask("##/##/####");
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        camDataFinal = new CampoMask("##/##/####");
        checkData = new javax.swing.JCheckBox();
        jPanel10 = new javax.swing.JPanel();
        radioBaixaSim = new javax.swing.JRadioButton();
        radioBaixaNao = new javax.swing.JRadioButton();
        checkBaixa = new javax.swing.JCheckBox();
        jPanel11 = new javax.swing.JPanel();
        radioPenhoraSim = new javax.swing.JRadioButton();
        radioPenhoraNao = new javax.swing.JRadioButton();
        checkPenhora = new javax.swing.JCheckBox();
        jPanel12 = new javax.swing.JPanel();
        radioComodatoSim = new javax.swing.JRadioButton();
        radioComodatoNao = new javax.swing.JRadioButton();
        checkComodato = new javax.swing.JCheckBox();
        barra = new javax.swing.JProgressBar();
        jPanel8 = new javax.swing.JPanel();
        jPanel13 = new javax.swing.JPanel();
        radioAnalitico = new javax.swing.JRadioButton();
        radioSintetico = new javax.swing.JRadioButton();
        jPanel14 = new javax.swing.JPanel();
        camOrdem = new javax.swing.JComboBox();
        botGerar = new javax.swing.JButton();
        botCancelar = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Relatório de Bens");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Filtros", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Área", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        checkArea.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkAreaActionPerformed(evt);
            }
        });

        camArea.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camArea.setEnabled(false);
        camArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                camAreaActionPerformed(evt);
            }
        });

        camAreaNum.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camAreaNum.setEnabled(false);
        camAreaNum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                camAreaNumActionPerformed(evt);
            }
        });
        camAreaNum.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                camAreaNumFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                camAreaNumFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkArea)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(camAreaNum, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(camArea, 0, 304, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkArea)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(camArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(camAreaNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Grupo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        checkGrupo.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkGrupoActionPerformed(evt);
            }
        });

        camGrupo.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camGrupo.setEnabled(false);
        camGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                camGrupoActionPerformed(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Subgrupo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        checkSubgrupo.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkSubgrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkSubgrupoActionPerformed(evt);
            }
        });

        camSubgrupo.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camSubgrupo.setEnabled(false);
        camSubgrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                camSubgrupoActionPerformed(evt);
            }
        });

        camSubgrupoNum.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camSubgrupoNum.setEnabled(false);
        camSubgrupoNum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                camSubgrupoNumActionPerformed(evt);
            }
        });
        camSubgrupoNum.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                camSubgrupoNumFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                camSubgrupoNumFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkSubgrupo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(camSubgrupoNum, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(camSubgrupo, 0, 272, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkSubgrupo)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(camSubgrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(camSubgrupoNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        camGrupoNum.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camGrupoNum.setEnabled(false);
        camGrupoNum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                camGrupoNumActionPerformed(evt);
            }
        });
        camGrupoNum.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                camGrupoNumFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                camGrupoNumFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(checkGrupo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(camGrupoNum, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(camGrupo, 0, 300, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkGrupo)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(camGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(camGrupoNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Fornecedor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        checkFornecedor.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkFornecedorActionPerformed(evt);
            }
        });

        camFornecedor.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camFornecedor.setEnabled(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkFornecedor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(camFornecedor, 0, 345, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkFornecedor)
                    .addComponent(camFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Setor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        checkSetor.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkSetor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkSetorActionPerformed(evt);
            }
        });

        camSetor.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camSetor.setEnabled(false);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkSetor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(camSetor, 0, 345, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkSetor)
                    .addComponent(camSetor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Órgão", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        checkOrgao.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkOrgao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkOrgaoActionPerformed(evt);
            }
        });

        camOrgao.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camOrgao.setEnabled(false);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkOrgao)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(camOrgao, 0, 267, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkOrgao)
                    .addComponent(camOrgao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data de Entrada", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        camDataInicial.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camDataInicial.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        camDataInicial.setText("25032004");
        camDataInicial.setEnabled(false);
        camDataInicial.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                camDataInicialFocusLost(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Segoe UI", 0, 13));
        jLabel5.setText("De");

        jLabel6.setFont(new java.awt.Font("Segoe UI", 0, 13));
        jLabel6.setText("à");

        camDataFinal.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camDataFinal.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        camDataFinal.setText("25032004");
        camDataFinal.setEnabled(false);
        camDataFinal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                camDataFinalFocusLost(evt);
            }
        });

        checkData.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkDataActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkData)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(camDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addComponent(camDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(camDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6)
                        .addComponent(camDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5))
                    .addComponent(checkData))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Baixa", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        grupoBaixa.add(radioBaixaSim);
        radioBaixaSim.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioBaixaSim.setSelected(true);
        radioBaixaSim.setText("SIM");
        radioBaixaSim.setEnabled(false);

        grupoBaixa.add(radioBaixaNao);
        radioBaixaNao.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioBaixaNao.setText("NÃO");
        radioBaixaNao.setEnabled(false);

        checkBaixa.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkBaixa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBaixaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkBaixa)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radioBaixaSim)
                .addGap(18, 18, 18)
                .addComponent(radioBaixaNao)
                .addContainerGap(159, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(checkBaixa)
            .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(radioBaixaSim)
                .addComponent(radioBaixaNao))
        );

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Penhora", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        grupoPenhora.add(radioPenhoraSim);
        radioPenhoraSim.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioPenhoraSim.setSelected(true);
        radioPenhoraSim.setText("SIM");
        radioPenhoraSim.setEnabled(false);

        grupoPenhora.add(radioPenhoraNao);
        radioPenhoraNao.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioPenhoraNao.setText("NÃO");
        radioPenhoraNao.setEnabled(false);

        checkPenhora.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkPenhora.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkPenhoraActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(checkPenhora)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radioPenhoraSim)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioPenhoraNao))
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkPenhora)
                    .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(radioPenhoraSim)
                        .addComponent(radioPenhoraNao)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Comodato", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        grupoComodato.add(radioComodatoSim);
        radioComodatoSim.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioComodatoSim.setSelected(true);
        radioComodatoSim.setText("SIM");
        radioComodatoSim.setEnabled(false);

        grupoComodato.add(radioComodatoNao);
        radioComodatoNao.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioComodatoNao.setText("NÃO");
        radioComodatoNao.setEnabled(false);

        checkComodato.setFont(new java.awt.Font("Segoe UI", 0, 13));
        checkComodato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkComodatoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(checkComodato)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radioComodatoSim)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioComodatoNao))
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkComodato)
                    .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(radioComodatoSim)
                        .addComponent(radioComodatoNao)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        barra.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                barraPropertyChange(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(barra, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                        .addComponent(barra, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opções", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tipo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        grupoTipo.add(radioAnalitico);
        radioAnalitico.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioAnalitico.setText("Analítico");

        grupoTipo.add(radioSintetico);
        radioSintetico.setFont(new java.awt.Font("Segoe UI", 0, 13));
        radioSintetico.setSelected(true);
        radioSintetico.setText("Sintético");

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(radioAnalitico)
                .addGap(18, 18, 18)
                .addComponent(radioSintetico)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioAnalitico)
                    .addComponent(radioSintetico))
                .addContainerGap())
        );

        jPanel14.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ordenar Por", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 13))); // NOI18N

        camOrdem.setFont(new java.awt.Font("Segoe UI", 0, 13));
        camOrdem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Descrição", "Data de Entrada" }));

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(camOrdem, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addComponent(camOrdem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botGerar.setFont(new java.awt.Font("Segoe UI", 0, 13)); // NOI18N
        botGerar.setText("Gerar Relatório");
        botGerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botGerarActionPerformed(evt);
            }
        });

        botCancelar.setFont(new java.awt.Font("Segoe UI", 0, 13));
        botCancelar.setText("Cancelar");
        botCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
                .addComponent(botCancelar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botGerar)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel14, 0, 64, Short.MAX_VALUE)
                    .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(botGerar)
                            .addComponent(botCancelar))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-758)/2, (screenSize.height-537)/2, 758, 537);
    }// </editor-fold>//GEN-END:initComponents

    private void checkAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkAreaActionPerformed
        if (checkArea.isSelected()) {
            camArea.setEnabled(true);
            camAreaNum.setEnabled(true);
        } else {
            camArea.setEnabled(false);
            camAreaNum.setEnabled(true);
        }
}//GEN-LAST:event_checkAreaActionPerformed

    private void checkGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkGrupoActionPerformed
        if (checkGrupo.isSelected()) {
            camGrupo.setEnabled(true);
            camGrupoNum.setEnabled(true);
            checkSubgrupo.setEnabled(true);
        } else {
            camGrupo.setEnabled(false);
            camGrupoNum.setEnabled(false);
            checkSubgrupo.setEnabled(false);
        }
}//GEN-LAST:event_checkGrupoActionPerformed

    private void checkFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkFornecedorActionPerformed
        if (checkFornecedor.isSelected()) {
            camFornecedor.setEnabled(true);
        } else {
            camFornecedor.setEnabled(false);
        }
}//GEN-LAST:event_checkFornecedorActionPerformed

    private void checkSubgrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSubgrupoActionPerformed
        if (checkSubgrupo.isSelected()) {
            camSubgrupo.setEnabled(true);
            camSubgrupoNum.setEnabled(true);
        } else {
            camSubgrupo.setEnabled(false);
            camSubgrupoNum.setEnabled(false);
        }
}//GEN-LAST:event_checkSubgrupoActionPerformed

    private void checkSetorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSetorActionPerformed
        if (checkSetor.isSelected()) {
            camSetor.setEnabled(true);
        } else {
            camSetor.setEnabled(false);
        }
}//GEN-LAST:event_checkSetorActionPerformed

    private void checkOrgaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkOrgaoActionPerformed
        if (checkOrgao.isSelected()) {
            camOrgao.setEnabled(true);
        } else {
            camOrgao.setEnabled(false);
        }
}//GEN-LAST:event_checkOrgaoActionPerformed

    private void camDataInicialFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camDataInicialFocusLost
        
}//GEN-LAST:event_camDataInicialFocusLost

    private void camDataFinalFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camDataFinalFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_camDataFinalFocusLost

    private void checkBaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBaixaActionPerformed
        if (checkBaixa.isSelected()) {
            radioBaixaSim.setEnabled(true);
            radioBaixaNao.setEnabled(true);
        } else {
            radioBaixaSim.setEnabled(false);
            radioBaixaNao.setEnabled(false);
        }
}//GEN-LAST:event_checkBaixaActionPerformed

    private void checkPenhoraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkPenhoraActionPerformed
        if (checkPenhora.isSelected()) {
            radioPenhoraSim.setEnabled(true);
            radioPenhoraNao.setEnabled(true);
        } else {
            radioPenhoraSim.setEnabled(false);
            radioPenhoraNao.setEnabled(false);
        }
}//GEN-LAST:event_checkPenhoraActionPerformed

    private void checkComodatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkComodatoActionPerformed
        if (checkComodato.isSelected()) {
            radioComodatoSim.setEnabled(true);
            radioComodatoNao.setEnabled(true);
        } else {
            radioComodatoSim.setEnabled(false);
            radioComodatoNao.setEnabled(false);
        }
}//GEN-LAST:event_checkComodatoActionPerformed

    private void botGerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botGerarActionPerformed
        botCancelar.setEnabled(true);
        botGerar.setEnabled(false);
        gr = new GeradorRelatorio();
        gr.setBarra(barra);
        if (radioAnalitico.isSelected()) {
            gr.setSQL(montaSQL("ana"));
            gr.setRelatorio("relatorio_analitico");
            //gr.gerarRelatorio(montaSQL("ana"), "relatorio_analitico");
        } else {
            gr.setSQL(montaSQL("sin"));
            gr.setRelatorio("relatorio_sintetico");
            //gr.gerarRelatorio(montaSQL("sin"), "relatorio_sintetico");
        }        
        barra.setStringPainted(true);
        thread = new Thread(gr);
        thread.start();
}//GEN-LAST:event_botGerarActionPerformed

    private void checkDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkDataActionPerformed
        if (checkData.isSelected()) {
            camDataInicial.setEnabled(true);
            camDataFinal.setEnabled(true);
            camDataInicial.requestFocus();
        } else {
            camDataInicial.setEnabled(false);
            camDataFinal.setEnabled(false);
        }
}//GEN-LAST:event_checkDataActionPerformed

    private void camGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camGrupoActionPerformed
        try {
            trocarSubgrupos();
            camGrupoNum.setText(Integer.toString(toGrupo.get(camGrupo.getSelectedIndex()).getNumero()));
        } catch (Exception e) {}        
    }//GEN-LAST:event_camGrupoActionPerformed

    private void botCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botCancelarActionPerformed
        cancelarThread();
}//GEN-LAST:event_botCancelarActionPerformed

    private void barraPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_barraPropertyChange
        if (!barra.isIndeterminate()) {
            botCancelar.setEnabled(false);
            botGerar.setEnabled(true);
            gr = null;
        }
    }//GEN-LAST:event_barraPropertyChange

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        if (barra.isIndeterminate()) {
            if (JOptionPane.showConfirmDialog(null, "Um relatório está sendo gerado, deseja realmente sair?")==0){
                cancelarThread();
                dispose();
            }
        } else {
            dispose();
        }
    }//GEN-LAST:event_formInternalFrameClosing

    private void camAreaNumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camAreaNumActionPerformed
        camArea.requestFocus();
}//GEN-LAST:event_camAreaNumActionPerformed

    private void camAreaNumFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camAreaNumFocusGained
        camGrupoNum.selectAll();
}//GEN-LAST:event_camAreaNumFocusGained

    private void camAreaNumFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camAreaNumFocusLost
        if (!setarCombo(camAreaNum.getText(), "Área", toArea, camArea)) {
            camArea.setSelectedIndex(0);
            camAreaNum.setText(Integer.toString(toArea.get(0).getNumero()));
            camAreaNum.requestFocus();
        }
}//GEN-LAST:event_camAreaNumFocusLost

    private void camGrupoNumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camGrupoNumActionPerformed
        camGrupo.requestFocus();
}//GEN-LAST:event_camGrupoNumActionPerformed

    private void camGrupoNumFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camGrupoNumFocusGained
        camGrupoNum.selectAll();
}//GEN-LAST:event_camGrupoNumFocusGained

    private void camGrupoNumFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camGrupoNumFocusLost
        if (!setarCombo(camGrupoNum.getText(), "Grupo", toGrupo, camGrupo)) {
            camGrupo.setSelectedIndex(0);
            camGrupoNum.setText(Integer.toString(toGrupo.get(0).getNumero()));
            camGrupoNum.requestFocus();
        }
}//GEN-LAST:event_camGrupoNumFocusLost

    private void camSubgrupoNumFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camSubgrupoNumFocusGained
        camSubgrupoNum.selectAll();
}//GEN-LAST:event_camSubgrupoNumFocusGained

    private void camSubgrupoNumFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_camSubgrupoNumFocusLost
        if (!setarCombo(camSubgrupoNum.getText(), "Subgrupo", toSubgrupo, camSubgrupo)) {
            camSubgrupo.setSelectedIndex(0);
            camSubgrupoNum.setText(Integer.toString(toSubgrupo.get(0).getNumero()));
            camSubgrupoNum.requestFocus();
        }
}//GEN-LAST:event_camSubgrupoNumFocusLost

    private void camAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camAreaActionPerformed
        try {
            camAreaNum.setText(Integer.toString(toArea.get(camArea.getSelectedIndex()).getNumero()));
        } catch (Exception e) {}
    }//GEN-LAST:event_camAreaActionPerformed

    private void camSubgrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camSubgrupoActionPerformed
        try {
            camSubgrupoNum.setText(Integer.toString(toSubgrupo.get(camSubgrupo.getSelectedIndex()).getNumero()));
        } catch (Exception e) {}
    }//GEN-LAST:event_camSubgrupoActionPerformed

    private void camSubgrupoNumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camSubgrupoNumActionPerformed
        camSubgrupo.requestFocus();
    }//GEN-LAST:event_camSubgrupoNumActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar barra;
    private javax.swing.JButton botCancelar;
    private javax.swing.JButton botGerar;
    private javax.swing.JComboBox camArea;
    private javax.swing.JTextField camAreaNum;
    private javax.swing.JTextField camDataFinal;
    private javax.swing.JTextField camDataInicial;
    private javax.swing.JComboBox camFornecedor;
    private javax.swing.JComboBox camGrupo;
    private javax.swing.JTextField camGrupoNum;
    private javax.swing.JComboBox camOrdem;
    private javax.swing.JComboBox camOrgao;
    private javax.swing.JComboBox camSetor;
    private javax.swing.JComboBox camSubgrupo;
    private javax.swing.JTextField camSubgrupoNum;
    private javax.swing.JCheckBox checkArea;
    private javax.swing.JCheckBox checkBaixa;
    private javax.swing.JCheckBox checkComodato;
    private javax.swing.JCheckBox checkData;
    private javax.swing.JCheckBox checkFornecedor;
    private javax.swing.JCheckBox checkGrupo;
    private javax.swing.JCheckBox checkOrgao;
    private javax.swing.JCheckBox checkPenhora;
    private javax.swing.JCheckBox checkSetor;
    private javax.swing.JCheckBox checkSubgrupo;
    private javax.swing.ButtonGroup grupoBaixa;
    private javax.swing.ButtonGroup grupoComodato;
    private javax.swing.ButtonGroup grupoPenhora;
    private javax.swing.ButtonGroup grupoTipo;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JRadioButton radioAnalitico;
    private javax.swing.JRadioButton radioBaixaNao;
    private javax.swing.JRadioButton radioBaixaSim;
    private javax.swing.JRadioButton radioComodatoNao;
    private javax.swing.JRadioButton radioComodatoSim;
    private javax.swing.JRadioButton radioPenhoraNao;
    private javax.swing.JRadioButton radioPenhoraSim;
    private javax.swing.JRadioButton radioSintetico;
    // End of variables declaration//GEN-END:variables

}
